home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / dissociate < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  2.0 KB  |  86 lines

  1. #!/bin/ksh
  2. # @(#) dissociate.ksh 1.1 95/06/17
  3. # 92/09/15 John H. DuBois III (john@armory.com)
  4. # 95/06/17 Added fioe option.
  5.  
  6. name=${0##*/}
  7. Usage=\
  8. "Usage: $name [-hp] [-f<filename>] [-i<input-file>] [-o<output-file>]
  9.        [-e<error-file>] command arg ..."
  10. PrintPID=false
  11. file=/dev/null
  12. input= output= error=
  13.  
  14. while getopts :hpf:i:o:e: opt; do
  15.     case $opt in
  16.     h)
  17.     echo \
  18. "$name: execute a process disconnected from any tty.
  19. $Usage
  20. command is executed with /dev/null opened for standard input, output, and
  21. error.  It will initially belong to its own process group with no controlling
  22. tty.  The command is executed asynchronously, so it will not be waited for.
  23. Its parent will be process 1 (init).
  24. A check is done to make sure that command is executable.
  25. Any other errors that prevent command from being executed will not be
  26. reported, since they will occur after error output has been redirected.
  27. Options:
  28. -f<filename>: Open <filename> for the standard input, output, and error files.
  29. -[ioe]<filename>: Open the given file for standard input, output, or error.
  30.     These assignments override a filename given with -f.
  31. -h: print this help.
  32. -p: print the process ID of the executed command."
  33.     exit 0
  34.     ;;
  35.     f)
  36.     file=$OPTARG
  37.     ;;
  38.     i)
  39.     input=$OPTARG
  40.     ;;
  41.     o)
  42.     output=$OPTARG
  43.     ;;
  44.     e)
  45.     error=$OPTARG
  46.     ;;
  47.     p)
  48.     PrintPID=true
  49.     ;;
  50.     +?)
  51.     print -u2 "$name: options should not be preceded by a '+'."
  52.     exit 1
  53.     ;;
  54.     :) 
  55.     print -r -u2 -- \
  56.     "$name: Option '$OPTARG' requires a value.  Use -h for help."
  57.     exit 1
  58.     ;;
  59.     ?) 
  60.     print -u2 "$name: $OPTARG: bad option.  Use -h for help."
  61.     exit 1
  62.     ;;
  63.     esac
  64. done
  65.  
  66. # remove args that were options
  67. let OPTIND=OPTIND-1
  68. shift $OPTIND
  69.  
  70. if [ $# -lt 1 ]; then
  71.     print -u2 "$Usage\nUse -h for help."
  72.     exit 1
  73. fi
  74.  
  75. if type "$1" > /dev/null; then :; else
  76.     echo "$name: Cannot execute $1.  Aborting." 1>&2
  77.     exit 1
  78. fi
  79.  
  80. [ -z "$input" ] && input=$file
  81. [ -z "$output" ] && output=$file
  82. [ -z "$error" ] && error=$file
  83.  
  84. /bin/setpgrp "$@" <"$input" >"$output" 2>"$error" &
  85. $PrintPID && echo $!
  86.